package query

import (
	"context"

	"server_1.0/api/internal/svc"
	"server_1.0/api/internal/types"
	"server_1.0/service/class/class"
	"server_1.0/util"

	"github.com/zeromicro/go-zero/core/logx"
)

type QueryClassNoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewQueryClassNoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryClassNoLogic {
	return &QueryClassNoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *QueryClassNoLogic) QueryClassNo(req *types.ClsQueryNoReq) (resp *types.PostReps, err error) {
	Resp, _ := l.svcCtx.ClassRpc.QueryID(l.ctx, &class.QueryIDReq{
		No: req.Cno,
	})
	code := util.Success
	Msg := "成功"
	if Resp.Count == 0 {
		code = util.NoFoundError
		Msg = "无记录"
	}

	return &types.PostReps{
		Code: code,
		Msg:  Msg,
		Data: map[string]interface{}{
			"count": Resp.Count,
			"res":   Resp.QRs,
		},
	}, nil
}
